﻿var type = getCookie('jiangjin').split("&")[3].split("=")[1];
var columns, table, Serch
$(function () {
	if (type == '8d837dd9129e826c0bee7bcdd763c0b8') {
		columns = [{ "data": "OrderNo", render: function (value, type, row) { return '<a href="javascript:void(0)" onclick="OrderPro(&apos;' + row.OrderNo + '&apos;)">' + value + '</a>' } }, { "data": "Type" }, { "data": "BuyType" }, { "data": "UserNo" }, { "data": "UserName" }, { "data": "AddPC" }, { "data": "PV" }, { "data": "AddDT" }]
		$("#exampleAccordion>li:nth-child(3)").addClass("active");
	}
	else {
		columns = [{ "data": "OrderNo", render: function (value, type, row) { return '<a href="javascript:void(0)" onclick="OrderPro(&apos;' + row.OrderNo + '&apos;)">' + value + '</a>' } }, { "data": "Type" }, { "data": "BuyType" }, { "data": "UserNo" }, { "data": "UserName" }, { "data": "AddPC" }, { "data": "PV" }, { "data": "AddDT" }, {
			"data": "MId",
			render: function (value, type, row) {

				if (row.State > 0 && row.State != 2) {
					if (row.UserNo == "无") {
						return '<a href="javascript:void(0)" class="btn btn-primary btn-sm" onclick="ApplyAccount(&apos;' + row.Id + '&apos;)">申请账号</a>'
					} else {
						return '<span>已申请</span>'
					}
				} else if (row.State !== 2) {
					return '<span>已取消</span>'
				}
				else {
					return '<span>未受理</span>'
				}
			}
		}];
		if (type != "07332506fa00992798c91411c89023a8") {
			$("#exampleAccordion>li:nth-child(3) a").removeClass("collapsed");
			$("#exampleAccordion>li:nth-child(3) ul").addClass("show");
			$("#exampleAccordion>li:nth-child(3) ul>li:nth-child(2)").addClass("active");
		} else {
			$("#exampleAccordion>li:nth-child(6) a").removeClass("collapsed");
			$("#exampleAccordion>li:nth-child(6) ul").addClass("show");
			$("#exampleAccordion>li:nth-child(6) ul>li:nth-child(3)").addClass("active");
		}
	}
	table = $('#dataTable').dataTable({
		"sScrollX": "100%",
		"bScrollCollapse": true,
		"serverSide": true,
		"processing": true,
		"bFilter": false,
		"ordering": false,
		"stateSave": false,
		"deferRender": true,
		"stateDuration": 60 * 60 * 24,
		"pagingType": "simple_numbers",  //分页样式：simple,simple_numbers,full,full_numbers
		ajax: function (data, callback, settings) {
			//封装请求参数
			var param = {};
			param.size = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
			//param.start = data.start;//开始的记录序号
			param.index = (data.start / data.length) + 1;//当前页码
			param.key = $("#Search").val();
			param.startDT = $("#SDate").val();
			param.endDT = $("#EndDate").val();
			$.ajax({
				type: "POST",
				url: '/Order/PartialOrder',//
				cache: false,  //禁用缓存
				data: param,  //传入组装的参数
				dataType: "json",
				success: function (result) {
					//setTimeout仅为测试延迟效果
					//封装返回数据
					var returnData = {};
					returnData.draw = data.draw;//这里直接自行返回了draw计数器,应该由后台返回
					returnData.recordsTotal = result.total;//返回数据全部记录
					returnData.recordsFiltered = result.total;//后台不实现过滤功能，每次查询均视作全部结果
					returnData.data = result.Data;//返回的数据列表
					//console.log(returnData);
					//调用DataTables提供的callback方法，代表数据已封装完成并传回DataTables进行渲染
					//此时的数据需确保正确无误，异常判断应在执行此回调前自行处理完毕
					callback(returnData);
				},
				error: function (XMLHttpRequest, textStatus, errorThrown) {
					layer.msg("请求服务器出错")
				}
			});
		},
		//列表表头字段
		columns: columns,
		"oLanguage": { //国际化配置  
			"sProcessing": "正在获取数据，请稍后...",
			"sLengthMenu": "显示 _MENU_ 条",
			"sZeroRecords": "没有您要的内容",
			"sInfo": "从 _START_ 到  _END_ 条 总共 _TOTAL_ 条",
			"sInfoEmpty": "记录数为0",
			"sInfoFiltered": "(全部记录数 _MAX_ 条)",
			"sInfoPostFix": "",
			"sSearch": "搜索",
			"sUrl": "",
			"oPaginate": {
				"sFirst": "第一页",
				"sPrevious": "上一页",
				"sNext": "下一页",
				"sLast": "最后一页"
			}
		},
	}).api();
	$("#dataTable_wrapper .row:last-child").addClass("mt-2");
})

function ApplyAccount(id) {
	layer.open({
		type: 2,
		title: '账号注册',
		shadeClose: true,
		shade: 0.8,
		area: ['40%', '75%'],
		content: '/Register/Index/?id=' + id //iframe的url
	});
}

//时间搜索
$("#dateSearch").click(function (event) {
	var SDate = $("#SDate").val();
	var endDate = $("#EndDate").val();
	table.ajax.reload();
});
//导出
$("#dateDeriveExcel").click(function (event) {
	var SDates = $("#SDate").val();
	var endDates = $("#EndDate").val();
	if (SDates == undefined || SDates == "") {
		layer.msg('请输入开始时间');
		return false
	}
	if (endDates == undefined || endDates == "") {
		layer.msg('请输入结束时间');
		return false
	}
	$.post("/Excel/ExportOrder", { starteDT: SDates, endDT: endDates }, function (data) {
		layer.msg(data.Msg);
	})
});
//详情
function OrderPro(id) {
	layer.open({
		type: 2,
		title: '订单详情',
		shadeClose: true,
		shade: 0.8,
		area: ['40%', '80%'],
		content: '/Order/OrderPro/?id=' + id //iframe的url
	});
}

